import zipfile
import os
import pyminizip

def compress_to_zip(file_path_list, des_path=r'./secret.zip', passwd=''):
    # 压缩文件

    # 将一个文件写入到zip包中
    zipFile = des_path
    zipTask2 = zipfile.ZipFile(zipFile, 'a', zipfile.ZIP_DEFLATED)
    # 待写入的文件路径
    for path in file_path_list:
        zipTask2.write(path)
    # 关闭
    zipTask2.close()

    # input file path
    inpt = des_path
    # prefix path
    pre = None
    # output zip file path
    oupt = "./output.zip"
    # set password value
    if passwd == '':
        password = None
    else:
        password = passwd
    # compress level
    com_lvl = 5
    # compressing file
    pyminizip.compress(inpt, None, oupt, password, com_lvl)
    os.remove(des_path)

def unpress_zip(source_path=r'./my_decode.zip',passwd=''):
    # 解压文件：
    zipFile = source_path
    targetDir = r'./extra'

    zipTask3 = zipfile.ZipFile(zipFile,'r',zipfile.ZIP_DEFLATED)
    pwd = passwd.encode()
    if passwd != '':
        zipTask3.setpassword(pwd)
    zipTask3.extractall(targetDir)
    zipTask3.close()


if __name__ == "__main__":
    compress_to_zip([r'./testfile/t.file', r'./testfile/t.7z'], passwd='mylove')
    unpress_zip(passwd='mylove')